$APPTYPE GUI
$TYPECHECK ON
$OPTIMIZE ON
$INCLUDE <RAPIDQ.INC>
$INCLUDE "FUNCIONES.BAS"
$INCLUDE "CONFIGURARDB.FORM"
$INCLUDE "ALTACLIENTES.FORM"
$INCLUDE "ACERCADE.FORM"
$INCLUDE "BAJACLIENTES.FORM"
$INCLUDE "MODIFICACLIENTES.FORM"
$INCLUDE "FACTURACION.FORM"
$INCLUDE "ADMINISTRARLEYENDAS.FORM"

DECLARE SUB ConfigurarDB
DECLARE SUB AdministrarLeyendas
DECLARE SUB Salir
DECLARE SUB AcercaDe
DECLARE SUB AltaClientes
DECLARE SUB BajaClientes
DECLARE SUB ModificaClientes(Sender AS QSTRINGGRID)
DECLARE SUB ActualizarGrid
DECLARE SUB Facturacion
DECLARE SUB SeleccionarCliente(col%, row%)

IF dbFile.Open("conndata.dat", fmOpenRead) = FALSE THEN
	ConfigurarDBForm.ShowModal
	
	MySQL.Connect(Host, User, Passwd)

	IF MySQL.Connected THEN
		MySQL.SelectDB(DbName)
		MessageDLG("Conectado a " + Host, mtInformation, mbOk, 0)
	ELSE
		MessageDLG("Error al Conectarse a " + Host, mtError, mbOk, 0)
	END IF

ELSE
	dbFile.Close
END IF

CREATE MainForm AS QFORM
	ICOHandle = MAIN_ICO
	Center
	Width = 500
	Height = 500
	Caption = "SISTEMA DE FACTURACION V1.1"
	OnCLose = Salir
	OnShow = ActualizarGrid
	
	CREATE MenuPrincipal AS QMAINMENU
	
		CREATE MenuArchivo AS QMENUITEM
			Caption = "&Archivo"
			
			CREATE MenuConfigurarDB AS QMENUITEM
				Caption = "&Configurar Acceso a DB"
				OnClick = ConfigurarDB
			END CREATE
			
			CREATE MenuLeyenda AS QMENUITEM
				Caption = "&Administracion de Leyendas"
				OnClick = AdministrarLeyendas
			END CREATE
			
			CREATE MenuSalir AS QMENUITEM
				Caption = "&Salir"
				OnClick = Salir
			END CREATE			
		END CREATE
		
		CREATE MenuAcciones AS QMENUITEM
			Caption = "A&cciones"
			
			CREATE MenuClientes AS QMENUITEM
				Caption = "Administracion de Clientes"
				
				CREATE MenuAltaClientes AS QMENUITEM
					Caption = "Alta de Clientes"
					OnClick = AltaClientes
				END CREATE
				
				CREATE MenuBajaClientes AS QMENUITEM
					Caption = "Baja de Clientes"
					OnClick = BajaClientes
				END CREATE
				
				CREATE MenuModificaClientes AS QMENUITEM
					Caption = "Modificacion de Clientes"
					OnClick = ModificaClientes
				END CREATE
				
			END CREATE
			
			CREATE MenuFacturacion AS QMENUITEM
				Caption = "Administracion de Facturacion"
				OnClick = Facturacion
			END CREATE
		END CREATE
		
		CREATE MenuAyuda AS QMENUITEM
			Caption = "A&yuda"
			
			CREATE MenuAcercaDe AS QMENUITEM
				Caption = "Acerca &de"
				OnClick = AcercaDe
			END CREATE
		END CREATE
		
	END CREATE

	CREATE ClientesLabel AS QLABEL	
		Caption = "Clientes Existentes"
		Top = 5
		Left = 10
	END CREATE
		
	CREATE ClientesGrid AS QSTRINGGRID
		Top = 20
		Left = 2
		Width = 490
		Height = 350
		FixedRows = 1
		FixedCols = 0
		ColCount = 5
		DefaultRowHeight = 20
		DefaultColWidth = 96
		ColWidths(0) = 48
		ColWidths(2) = 144
		ColWidths(3) = 116
		ColWidths(4) = 76
		Cell(0, 0) = "CODIGO"
		Cell(1, 0) = "NOMBRE"
		Cell(2, 0) = "DIRECCION"
		Cell(3, 0) = "CAT. IVA"
		Cell(4, 0) = "CUIT"
		OnSelectCell = SeleccionarCliente
	END CREATE
	
	CREATE ActualizarGridButton AS QBUTTON
		Caption = "Actuali&zar"
		Top = 400
		Left = 200
		OnClick = ActualizarGrid
	END CREATE
	
	ShowModal
END CREATE
	
SUB ActualizarGrid
	MySQL2Grid(MySQL, ClientesGrid, "SELECT * FROM cliente")
END SUB

SUB Salir
	MySQL.Close
	END
END SUB

SUB ConfigurarDB
	ConfigurarDBForm.Show
END SUB

SUB AdministrarLeyendas
	AdministrarLeyendasForm.Show
END SUB

SUB AcercaDe
	AcercaDeForm.Show
END SUB

SUB AltaClientes
	AltaClientesForm.Show
END SUB

SUB BajaClientes
	BajaClientesForm.Show
END SUB

SUB ModificaClientes
	ModificaClientesForm.Show
END SUB

SUB Facturacion
	FacturacionForm.Show
END SUB

SUB SeleccionarCliente(col%, row%)
	Codigo = LTRIM$(RTRIM$(ClientesGrid.Cell(0, row%)))
END SUB